import { Module, Global } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { SentryService } from './sentry.service';

/**
 * Sentry 错误追踪模块
 * 基于 NestJS 官方示例实现
 * 参考: https://docs.nestjs.cn/fundamentals/dependency-injection
 * 对应 Java: 错误追踪配置
 */
@Global()
@Module({
  imports: [ConfigModule],
  providers: [
    {
      provide: SentryService,
      useFactory: (configService: ConfigService) => {
        const sentryConfig = configService.get('sentry');
        return new SentryService(sentryConfig);
      },
      inject: [ConfigService],
    },
  ],
  exports: [SentryService],
})
export class SentryModule {}
